package com.health.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.entity.RegisterOrder;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryRegisterOrderDTO;
import com.health.entity.pojo.vo.RegisterOrderDownloadVO;
import com.health.mapper.RegisterOrderMapper;
import com.health.service.IRegisterOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 挂号订单 服务实现类
 * </p>
 *
 * @author health
 * @since 2023-04-20
 */
@Service
public class RegisterOrderServiceImpl extends ServiceImpl<RegisterOrderMapper, RegisterOrder> implements IRegisterOrderService {

    @Override
    public PageData listPageRegisterOrder(QueryRegisterOrderDTO queryRegisterOrderDTO) {
        IPage<RegisterOrder> iPage = new Page<>(queryRegisterOrderDTO.getCurrentPage(), queryRegisterOrderDTO.getPageSize());
        IPage<RegisterOrder> page = baseMapper.listPageRegisterOrder(iPage, queryRegisterOrderDTO);
        return new PageData(page.getTotal(), page.getRecords());
    }

    @Override
    public List<RegisterOrderDownloadVO> listPageDownloadRegisterOrder(QueryRegisterOrderDTO queryRegisterOrderDTO) {
        List<RegisterOrderDownloadVO> list = new ArrayList<>();
        IPage<RegisterOrder> iPage = new Page<>(queryRegisterOrderDTO.getCurrentPage(), queryRegisterOrderDTO.getPageSize());
        IPage<RegisterOrder> page = baseMapper.listPageRegisterOrder(iPage, queryRegisterOrderDTO);
        List<RegisterOrder> list2 =  page.getRecords();
        for (RegisterOrder registerOrder : list2) {
            RegisterOrderDownloadVO temp = new RegisterOrderDownloadVO();
            BeanUtils.copyProperties(registerOrder, temp);
            list.add(temp);
        }
        return list;
    }

}
